import 'package:flutter/material.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/net/internet.dart';
import 'package:xiongan_app_yy/utils/toast_utils.dart';

//自动拣选Provider
class AutoPickingProvider extends ChangeNotifier {
  
  // _netStatus系列表示请求状态：
  // false未请求
  // true请求中

  bool _netStatus1 = false;
  List _listData=List(); //列表数据
  bool _down;
  bool _up;

  bool _netStatus2 = false;
  Map _detailListData=Map(); //详情列表数据

  Map<String,dynamic> _detailData=Map(); //详情数据

  List _lowerShelfList = List(); //下架某个类型列表
  
  //getter方法获取数据
  get netStatus1=>_netStatus1;
  get listData=>_listData;
  get down=>_down;

  get netStatus2=>_netStatus2;
  get detailListData=>_detailListData;
  get lowerShelfList=>_lowerShelfList;

  get detailData=>_detailData;

  //列表查询
  void getList({Map<String,dynamic> sendObj}) async {
    sendObj["warehouseid"] = DataSingleton().warehouseChoice.id;
    //sendObj["warehouseid"] = "a88638a710754671b4f460529f345764";
    //初始化数据和加载状态
    _netStatus1=true;
    _listData=[];
    notifyListeners();
    // print(DataSingleton().warehouseChoice.id);
    Map<String,dynamic> res = await Internet().get("WMS/MiWarehouseOutOrder/GetOutPickOrderList",params:sendObj);
    if(res['flag'] == "success"){
      _listData=res['datas'];
    }else{
      TostUtil.showToast(res['msg']);
    }
    _netStatus1=false;
    notifyListeners();
  }

  //详情列表多类型查询
  void getDetailListData({@required String orderid}) async {
    Map<String,dynamic> sendObj={
      "orderid":orderid
    };
    //初始化数据和加载状态
    _netStatus2=true;
    _detailListData.clear();
    notifyListeners();
    Map<String,dynamic> res = await Internet().get("WMS/MiWarehouseOutOrder/GetOutOrderWorkDetailInfo",params:sendObj);
    if(res['flag'] == "success"){
      _detailListData=res['datas']["outOrderDetailList"];
    }else{
    TostUtil.showToast(res['msg']);
    }
    _netStatus2=false;
    notifyListeners();
  }

  //保存类型列表数据
  void setTypeDetailData({@required List datas}) async {
  _lowerShelfList=datas;
    notifyListeners();
  }

  //详情数据
  void setDetailData({@required Map<String,dynamic> obj}) async {
    _detailData=obj;
    notifyListeners();
  }
  
  //上架
  Future<dynamic> sendOrderAutoPutqwayTask({Map<String,dynamic> sendObj}) async {
    Map<String,dynamic> res = await Internet().post("WMS/MiWarehouseOutOrder/SendAutoPickingDetailPutawayMaterial",params:sendObj);
    if(res['flag'] == "success"){
      TostUtil.showToast("上架成功");
    }else{
      TostUtil.showToast(res['msg']);
    }
    return res['datas'];
  }
  
  //下架
  Future<dynamic> sendOrderTakeMaterialTask({Map<String,dynamic> sendObj}) async {
    Map<String,dynamic> res = await Internet().post("WMS/MiWarehouseOutOrder/SendAutoPickingDetailTakeMaterial",params:sendObj);
    if(res['flag'] == "success"){
      TostUtil.showToast("下架成功");
    }else{
      TostUtil.showToast(res['msg']);
    }
    return res['datas'];
  }

  //提交
  Future<dynamic> SubmissionAutoPickingDetail({Map sendObj}) async {
    Map<String,dynamic> res = await Internet().post("WMS/MiWarehouseOutOrder/SubmissionAutoPickingDetail",params:sendObj);
    if(res['flag'] == "success"){
      TostUtil.showToast("提交成功");
    }else{
      TostUtil.showToast(res['msg']);
    }
    return res['datas'];
  }

}
